﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary
{
    /// <summary>
    /// Defines a function delegate to bind the method, which represents the function.
    /// </summary>
    public delegate ComplexNumber HardComplexFunctionPointer(ComplexNumber x);

    /// <summary>
    /// This class represents a complex function, which can be implemented by source code.
    /// </summary>
    [Serializable]
    public class HardComplexFunction : IComplexFunction
    {
        /// <summary>
        /// The pointer to the method, which represents the function.
        /// </summary>
        private HardComplexFunctionPointer hardComplexFunctionPointer;

        /// <summary>
        /// Initializes a new instance of the <see cref="HardComplexFunction"/> class.
        /// </summary>
        /// <param name="hardComplexFunctionPointer">The pointer to the method, which represents the function.</param>
        public HardComplexFunction(HardComplexFunctionPointer hardComplexFunctionPointer)
        {
            this.hardComplexFunctionPointer = hardComplexFunctionPointer;
        }

        /// <summary>
        /// Gets or sets the pointer to the method, which represents the function.
        /// </summary>
        /// <value>The pointer to the method, which represents the function.</value>
        public HardComplexFunctionPointer HardComplexFunctionPointer
        {
            get { return hardComplexFunctionPointer; }
            set { hardComplexFunctionPointer = value; }
        }

        /// <summary>
        /// Calculates the complex function at the specified value x.
        /// </summary>
        /// <param name="x">The specified value x.</param>
        /// <returns>The result of the complex function at the specified value x.</returns>
        public ComplexNumber SolveAt(ComplexNumber x)
        {
            return this.hardComplexFunctionPointer(x);
        }
    }
}